package com.banyou.banyou.base;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.Window;


import com.banyou.banyou.util.MyActivityManager;

import java.text.SimpleDateFormat;


/**
 * ----------BigGod be here!----------/
 * ***┏┓******┏┓*********
 * *┏━┛┻━━━━━━┛┻━━┓*******
 * *┃             ┃*******
 * *┃     ━━━     ┃*******
 * *┃             ┃*******
 * *┃  ━┳┛   ┗┳━  ┃*******
 * *┃             ┃*******
 * *┃     ━┻━     ┃*******
 * *┃             ┃*******
 * *┗━━━┓     ┏━━━┛*******
 * *****┃     ┃神兽保佑*****
 * *****┃     ┃代码无BUG！***
 * *****┃     ┗━━━━━━━━┓*****
 * *****┃              ┣┓****
 * *****┃              ┏┛****
 * *****┗━┓┓┏━━━━┳┓┏━━━┛*****
 * *******┃┫┫****┃┫┫********
 * *******┗┻┛****┗┻┛*********
 * ━━━━━━神兽出没━━━━━━
 * <p/>
 * 项目名称：My Application
 * 包名：com.yztc.a1602.myapplication.base
 * 类描述：所有Activity的父类
 * 创建人:luxin
 * 创建时间：2016-08-14
 * 修改人：luxin
 * 修改时间：2016-08-14
 * 修改备注：
 */
public abstract class BaseFragmentActivity<P extends BasePresenter> extends FragmentActivity {
    protected P mPresenter;
    protected AlertDialog mDialog;//弹出窗口
    protected Window mWindowDialog;//获取Dialog的window
    private static final int TEXT = 1, REPORT = 2;
    protected String mToken, mSignCode;
    private SimpleDateFormat mFormat = new SimpleDateFormat("MM月dd日 hh:mm:ss");
    public View mLayoutView;
    public int mLayoutViewId;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyActivityManager.getInstance().pushOneActivity(this);
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);//共享元素必备
        if (initLayout() != -1) {
            mLayoutViewId=initLayout();
            setContentView(initLayout());
        } else {
            mLayoutView=initLayoutView();
            setContentView(initLayoutView());
        }
        mPresenter = initPresenter();  //初始化Presenter
        SharedPreferences preferences = getSharedPreferences("login"
                , Activity.MODE_PRIVATE);   //全局Token获取
        mToken = preferences.getString("token", "");
        init(); //初始化
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(Color.BLACK);
        }
    }

    protected abstract P initPresenter();

    /**
     * 设置LayoutID
     *
     * @return LayoutID
     */
    protected abstract int initLayout();

    /**
     * 设置LayoutVIew
     *
     * @return
     */
    protected abstract View initLayoutView();

    /**
     * 所有BaseActivity的init方法
     */
    protected abstract void init();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MyActivityManager.getInstance().popOneActivity(this);
    }
}
